<?php

namespace App\Http\Middleware;

use Auth;
use Closure;

class CheckAdminLevel
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next, $flag){
        if (Auth::check() && Auth::user()->userRole->role->flag & $flag){
            return $next($request);
        }
        return redirect('/error/pass');
    }
}
